package com.rcadmin.busi.admin.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.rcadmin.busi.admin.ddl.SysParam;
import com.rcadmin.common.contant.IsEff;
import com.rcadmin.core.jpa.BaseDao;
import com.rcadmin.core.jpa.DaoException;

/**
 * 系统参数DAO
 * 
 * @author tansonlam
 * @createDate 2016年3月23日
 * 
 */
@Component
public class SysParamDao {
	@Resource
	private BaseDao baseDao;

	public SysParam findByRootCodeAndParamName(String rootCode, String paramName) {
		StringBuilder query = new StringBuilder();
		query.append("root_code = '").append(rootCode).append("'");
		query.append("and param_name = '").append(paramName).append("'");
		query.append("and iseff = '").append(IsEff.EFFECTIVE).append("'");
		return baseDao.findOne(query.toString(), SysParam.class);
	}

	public List<SysParam> getSysParamByRoot(String rootCode) {
		return baseDao.find("root_code='" + rootCode + "' and iseff="
				+ IsEff.EFFECTIVE + " order by seq", SysParam.class);
	}

	public SysParam getSysParam(String paramCode) {
		return baseDao.findOne("param_code='" + paramCode + "' and iseff="
				+ IsEff.EFFECTIVE, SysParam.class);
	}

	public List<SysParam> getAllSysParam() throws DaoException {
		return baseDao.find("", SysParam.class);
	}

}
